home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / pmllib21.zoo / pow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-12  |  615 b   |  51 lines

  1. /*
  2.     computes x^y.
  3.     uses log and exp
  4. */
  5.  
  6. #include    <errno.h>
  7. #define pow inline_pow
  8. #include    <math.h>
  9. #undef pow
  10. int errno;
  11.  
  12. #if __STDC__
  13. double log(double), exp(double);
  14. #else
  15. double log(), exp();
  16. #endif
  17.  
  18. double
  19. pow(x,y)
  20. double x, y;
  21. {
  22.     double temp;
  23.     long l;
  24.  
  25.     if (y == 0.) {
  26.         if (x == 0.) goto domain;
  27.         return 1.0;
  28.     }
  29.     else if (x == 0.) {
  30.         if (y > 0.) return 0.;
  31.         else goto domain;
  32.     }
  33.  
  34.     if(x < 0.)
  35.     {
  36.         l = y;            /* is y an integer? */
  37.         if(l != y)
  38.             goto domain;
  39.         temp = exp(y * log(-x));
  40.         if(l & 1)
  41.             temp = -temp;
  42.         return(temp);
  43.     }
  44.  
  45.     return(exp(y * log(x)));
  46.  
  47. domain:
  48.     errno = EDOM;
  49.     return(HUGE_VAL);
  50. }
  51.